package com.wnxy.consumer.controller;

import com.wnxy.common.entity.Stu;
import com.wnxy.common.result.Result;
import com.wnxy.stu.api.StuProductApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yellow docker
 * @since 2024-04-17
 */
@RestController
@RequestMapping("/consumer")
public class StuController {

    @Autowired
    private StuProductApi stuProductApi;

    @GetMapping("list")
    public Result list(){
        return stuProductApi.list();
    }

    /**
     *  如果我们的微服务 提供者挂了
     *        stuProductApi 这个请求  一直等待返回结果
     *        设置openfeign 的 超时  + HystrixCommand 的服务降级
     * @param id
     * @return
     */
    @GetMapping("list/{id}")
    public Result listById(@PathVariable Integer id){
        return stuProductApi.listById(id);
    }

    @GetMapping("list/{currentPage}/{pageSize}")
    public Result listByPages(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        return stuProductApi.listByPages(currentPage,pageSize);
    }

    @PostMapping("add")
    public Result add(@RequestBody Stu stu){
        return stuProductApi.add(stu);
    }

    @DeleteMapping ("remove/{id}")
    public Result remove(@PathVariable Integer id){
        return stuProductApi.remove(id);
    }

    @PutMapping("update")
    public Result update(@RequestBody Stu stu){
        return stuProductApi.update(stu);
    }
}
